package com.hsck.order.kds.setup.fragment.dyzd

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.hsck.order.kds.R
import com.hsck.order.kds.base.isnoam.view.BaseFragment
import com.hsck.order.kds.databinding.FragmentDyzdBinding
import com.hsck.order.kds.setup.SetupActivity
import com.hsck.order.kds.setup.adapter.DyzdAdapter

/**
 * 打印站点
 */
class DyzdFragment : BaseFragment<FragmentDyzdBinding>(), SetupActivity.UpdatableFragment {

    private val adapter by lazy { DyzdAdapter(R.layout.item_dyzd) }

    override fun inflateBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentDyzdBinding {
        return FragmentDyzdBinding.inflate(inflater)
    }

    override fun loadDataOnce() {
        super.loadDataOnce()
        binding.apply {
            rvDyzd.layoutManager = GridLayoutManager(requireActivity(), 2)
            rvDyzd.adapter = adapter
            adapter.datas = listOf("Add", "", "", "", "", "", "")
        }
        adapter.onItemClick = {
            var addDyzdFragment = AddDyzdFragment()//设备管理
            val activity = requireActivity() as SetupActivity
            if (it == "Add") {
                addDyzdFragment.type = "Add"
            } else {
                addDyzdFragment.type = "Edit"
            }
            addDyzdFragment.topFragment = this
            activity.switchFragment(addDyzdFragment)
        }
    }

    override fun onFragmentVisible() {
        //可见
        if (_binding != null) {

        }
    }

    override fun onFragmentInvisible() {
        //不可见

    }
}